package com.bank.maven.servlet;



import com.bank.maven.service.impl.userserviceImpl;
import com.bank.maven.service.userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/updataServlet")
public class updataServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String midStr = req.getParameter("mid");
        String id2Str = req.getParameter("id2");
        String moneyStr = req.getParameter("money");

        try {
            int id1 = Integer.parseInt(midStr);
            int id2 = Integer.parseInt(id2Str);
            int money1 = Integer.parseInt(moneyStr);

            userservice u = new userserviceImpl();
            u.updateuser(money1, id1, money1, id2);

        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
